/*
 * Created by JFormDesigner on Wed Jan 08 16:55:08 CST 2025
 */

package org.common.utils.generatortable.window;
import org.common.utils.generatortable.GeneratorTableManager;
import org.common.utils.generatortable.event.EventManager;
import org.common.utils.generatortable.event.entity.GeneratorEvent;
import org.common.utils.generatortable.event.entity.MysqlConnectionEvent;
import org.common.utils.generatortable.event.entity.SelectDirEvent;
import org.common.utils.generatortable.event.entity.WindowCloseEvent;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import org.jdesktop.beansbinding.*;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;

/**
 * @author GameAle
 */
public class GeneratorTableWindow extends JFrame {


    public GeneratorTableWindow() {
        GeneratorTableManager.getInstance().initBefore(this);
        initComponents();
        GeneratorTableManager.getInstance().initAfter(this);
    }

    private void txtHostFocusGained(FocusEvent e) {
        // TODO add your code here
    }

    private void txtHostFocusLost(FocusEvent e) {
        // TODO add your code here
    }

    private void btnConnectMouseClicked(MouseEvent e) {
        // TODO add your code here
    }

    private void btnGeneratorMousePressed(MouseEvent e) {
        // TODO add your code here
        EventManager.trigger(new GeneratorEvent());
    }

    private void btnConnectionMousePressed(MouseEvent e) {
        EventManager.trigger(new MysqlConnectionEvent());
        // TODO add your code here
    }

    private void txtGeneratorDirMousePressed(MouseEvent e) {
        // TODO add your code here
        EventManager.trigger(new SelectDirEvent(txtGeneratorDir , this));
    }

    private void thisWindowClosing(WindowEvent e) {
        // TODO add your code here
        EventManager.trigger(new WindowCloseEvent(this));
    }

    public GeneratorTableManager getManager() {
        return GeneratorTableManager.getInstance();
    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        ResourceBundle bundle = ResourceBundle.getBundle("localization");
        inputPanel = new JPanel();
        lblHost = new JLabel();
        txtMysqlHost = new JTextField();
        btnGenerator = new JButton();
        txtGeneratorDir = new JTextField();
        lblGeneratorPath = new JLabel();
        txtPackageName = new JTextField();
        lblGeneratorPackage = new JLabel();
        btnConnection = new JButton();
        lblPassword = new JLabel();
        txtUsername = new JTextField();
        txtPassword = new JPasswordField();
        lblUsername = new JLabel();
        scrollPane3 = new JScrollPane();
        txtAreaLog = new JTextArea();
        scrollPane1 = new JScrollPane();
        list1 = new JList();

        //======== this ========
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setTitle(bundle.getString("GeneratorTableWindow.this.title"));
        setFont(new Font("Al Bayan", Font.PLAIN, 11));
        setName("mainWindow");
        setResizable(false);
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                thisWindowClosing(e);
            }
        });
        var contentPane = getContentPane();
        contentPane.setLayout(null);

        //======== inputPanel ========
        {
            inputPanel.setLayout(null);

            //---- lblHost ----
            lblHost.setText(bundle.getString("GeneratorTableWindow.lblHost.text"));
            lblHost.setFont(new Font("Al Bayan", Font.PLAIN, 11));
            lblHost.setName("lblHost");
            lblHost.setHorizontalAlignment(SwingConstants.RIGHT);
            inputPanel.add(lblHost);
            lblHost.setBounds(new Rectangle(new Point(13, 13), lblHost.getPreferredSize()));

            //---- txtMysqlHost ----
            txtMysqlHost.setName("txtMysqlHost");
            txtMysqlHost.setToolTipText(bundle.getString("GeneratorTableWindow.txtMysqlHost.toolTipText"));
            txtMysqlHost.setText("10.30.126.161:3306/test");
            txtMysqlHost.addFocusListener(new FocusAdapter() {
                @Override
                public void focusGained(FocusEvent e) {
                    txtHostFocusGained(e);
                }
                @Override
                public void focusLost(FocusEvent e) {
                    txtHostFocusLost(e);
                }
            });
            inputPanel.add(txtMysqlHost);
            txtMysqlHost.setBounds(80, 5, 435, 30);

            //---- btnGenerator ----
            btnGenerator.setText(bundle.getString("GeneratorTableWindow.btnGenerator.text"));
            btnGenerator.setName("btnGenerator");
            btnGenerator.addMouseListener(new MouseAdapter() {
                @Override
                public void mousePressed(MouseEvent e) {
                    btnGeneratorMousePressed(e);
                }
            });
            inputPanel.add(btnGenerator);
            btnGenerator.setBounds(532, 77, 100, 60);

            //---- txtGeneratorDir ----
            txtGeneratorDir.setName("txtGeneratorDir");
            txtGeneratorDir.addMouseListener(new MouseAdapter() {
                @Override
                public void mousePressed(MouseEvent e) {
                    txtGeneratorDirMousePressed(e);
                }
            });
            inputPanel.add(txtGeneratorDir);
            txtGeneratorDir.setBounds(80, 75, 435, 30);

            //---- lblGeneratorPath ----
            lblGeneratorPath.setText(bundle.getString("GeneratorTableWindow.lblGeneratorPath.text"));
            lblGeneratorPath.setFont(new Font("Al Bayan", Font.PLAIN, 11));
            lblGeneratorPath.setName("lblUsername");
            lblGeneratorPath.setHorizontalAlignment(SwingConstants.RIGHT);
            inputPanel.add(lblGeneratorPath);
            lblGeneratorPath.setBounds(10, 85, 60, 14);

            //---- txtPackageName ----
            txtPackageName.setName("txtPackageName");
            inputPanel.add(txtPackageName);
            txtPackageName.setBounds(80, 110, 435, 30);

            //---- lblGeneratorPackage ----
            lblGeneratorPackage.setText(bundle.getString("GeneratorTableWindow.lblGeneratorPackage.text"));
            lblGeneratorPackage.setFont(new Font("Al Bayan", Font.PLAIN, 11));
            lblGeneratorPackage.setName("lblUsername");
            lblGeneratorPackage.setHorizontalAlignment(SwingConstants.RIGHT);
            inputPanel.add(lblGeneratorPackage);
            lblGeneratorPackage.setBounds(10, 120, 60, 14);

            //---- btnConnection ----
            btnConnection.setText(bundle.getString("GeneratorTableWindow.btnConnection.text"));
            btnConnection.addMouseListener(new MouseAdapter() {
                @Override
                public void mousePressed(MouseEvent e) {
                    btnConnectionMousePressed(e);
                }
            });
            inputPanel.add(btnConnection);
            btnConnection.setBounds(532, 8, 100, 60);

            //---- lblPassword ----
            lblPassword.setText(bundle.getString("GeneratorTableWindow.lblPassword.text"));
            lblPassword.setFont(new Font("Al Bayan", Font.PLAIN, 11));
            lblPassword.setHorizontalAlignment(SwingConstants.RIGHT);
            inputPanel.add(lblPassword);
            lblPassword.setBounds(10, 50, 60, 14);

            //---- txtUsername ----
            txtUsername.setName("txtUsername");
            txtUsername.setText("root");
            inputPanel.add(txtUsername);
            txtUsername.setBounds(80, 40, 180, 30);

            //---- txtPassword ----
            txtPassword.setName("txtPassword");
            txtPassword.setText("root");
            inputPanel.add(txtPassword);
            txtPassword.setBounds(335, 40, 180, 30);

            //---- lblUsername ----
            lblUsername.setText(bundle.getString("GeneratorTableWindow.lblPassword.text"));
            lblUsername.setFont(new Font("Al Bayan", Font.PLAIN, 11));
            lblUsername.setName("lblUsername");
            lblUsername.setHorizontalAlignment(SwingConstants.RIGHT);
            inputPanel.add(lblUsername);
            lblUsername.setBounds(265, 50, 60, 14);
        }
        contentPane.add(inputPanel);
        inputPanel.setBounds(280, 10, 645, 155);

        //======== scrollPane3 ========
        {

            //---- txtAreaLog ----
            txtAreaLog.setName("txtAreaLog");
            txtAreaLog.setFont(new Font("Al Bayan", Font.PLAIN, 10));
            scrollPane3.setViewportView(txtAreaLog);
        }
        contentPane.add(scrollPane3);
        scrollPane3.setBounds(285, 170, 625, 365);

        //======== scrollPane1 ========
        {

            //---- list1 ----
            list1.setName("list1");
            scrollPane1.setViewportView(list1);
        }
        contentPane.add(scrollPane1);
        scrollPane1.setBounds(15, 10, 255, 525);

        contentPane.setPreferredSize(new Dimension(930, 580));
        pack();
        setLocationRelativeTo(null);

        //---- bindings ----
        bindingGroup = new BindingGroup();
        bindingGroup.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ_WRITE,
            this, BeanProperty.create("manager.dataManager.dataEntity.mysqlHost"),
            txtMysqlHost, BeanProperty.create("text")));
        bindingGroup.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ_WRITE,
            this, BeanProperty.create("manager.dataManager.dataEntity.mysqlUsername"),
            txtUsername, BeanProperty.create("text")));
        bindingGroup.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ_WRITE,
            this, BeanProperty.create("manager.dataManager.dataEntity.mysqlPassword"),
            txtPassword, BeanProperty.create("text")));
        bindingGroup.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ_WRITE,
            this, BeanProperty.create("manager.dataManager.dataEntity.javaDir"),
            txtGeneratorDir, BeanProperty.create("text")));
        bindingGroup.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ_WRITE,
            this, BeanProperty.create("manager.dataManager.dataEntity.packageName"),
            txtPackageName, BeanProperty.create("text")));
        bindingGroup.bind();
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JPanel inputPanel;
    private JLabel lblHost;
    private JTextField txtMysqlHost;
    private JButton btnGenerator;
    private JTextField txtGeneratorDir;
    private JLabel lblGeneratorPath;
    private JTextField txtPackageName;
    private JLabel lblGeneratorPackage;
    private JButton btnConnection;
    private JLabel lblPassword;
    private JTextField txtUsername;
    private JPasswordField txtPassword;
    private JLabel lblUsername;
    private JScrollPane scrollPane3;
    private JTextArea txtAreaLog;
    private JScrollPane scrollPane1;
    private JList list1;
    private BindingGroup bindingGroup;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
